﻿' Copyright (C) 2015 HTTPBuilder
'
' This program is free software: you can redistribute it and/or modify it under the +terms 
' of the GNU General Public License as published by the Free Software Foundation, either 
' version 3 of the License, or (at your option) any later version.

' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
' without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
' See the GNU General Public License for more details.

' You should have received a copy of the GNU General Public License along with this program.
' If not, see http://www.gnu.org/licenses/. 

Imports System.Runtime.InteropServices
Imports System.Text

Namespace Interop
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <remarks></remarks>
    Friend Module NativeMethods

#Region "GDI Functions"
        <DllImport("gdi32.dll", EntryPoint:="CreateCompatibleDC", CallingConvention:=CallingConvention.StdCall)> _
        Public Function CreateCompatibleDC(ByVal hdc As IntPtr) As IntPtr
        End Function

        <DllImport("gdi32.dll", EntryPoint:="DeleteDC", CallingConvention:=CallingConvention.StdCall)> _
        Public Function DeleteDC(ByVal hdc As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
        End Function

        <DllImport("gdi32.dll", EntryPoint:="CreateCompatibleBitmap", CallingConvention:=CallingConvention.StdCall)> _
        Public Function CreateCompatibleBitmap(ByVal hdc As IntPtr, ByVal nWidth As Integer, ByVal nHeight As Integer) As IntPtr
        End Function

        <DllImport("gdi32.dll", EntryPoint:="SelectObject", CallingConvention:=CallingConvention.StdCall)> _
        Public Function SelectObject(ByVal hdc As IntPtr, ByVal hgdiobj As IntPtr) As IntPtr
        End Function

        <DllImport("gdi32.dll", EntryPoint:="DeleteObject", CallingConvention:=CallingConvention.StdCall)> _
        Public Function DeleteObject(ByVal hObject As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
        End Function

        <DllImport("gdi32.dll", EntryPoint:="StretchBlt", CallingConvention:=CallingConvention.StdCall)> _
        Public Function StretchBlt(ByVal hdcDest As IntPtr, ByVal nXOriginDest As Integer, ByVal nYOriginDest As Integer, _
                                       ByVal nWidthDest As Integer, ByVal nHeightDest As Integer, ByVal hdcSrc As IntPtr, _
                                       ByVal nXOriginSrc As Integer, ByVal nYOriginSrc As Integer, ByVal nWidthSrc As Integer, ByVal nHeightSrc As Integer, _
                                       ByVal dwRop As UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
        End Function

        <DllImport("gdi32.dll", EntryPoint:="BitBlt", CallingConvention:=CallingConvention.StdCall)> _
        Public Function BitBlt(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, _
                                   ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, _
                                   ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
                                   ByVal dwRop As UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
        End Function

        'Some raster operations
        Public Const SRCCOPY As UInteger = &HCC0020

        <DllImport("gdi32.dll", EntryPoint:="GetPixel", CallingConvention:=CallingConvention.StdCall)> _
        Public Function GetPixel(ByVal hdc As IntPtr, ByVal nXPos As Integer, ByVal nYPos As Integer) As UInteger
        End Function

        <DllImport("gdi32.dll", EntryPoint:="SetPixel", CallingConvention:=CallingConvention.StdCall)> _
        Public Function SetPixel(ByVal hdc As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal crColor As UInteger) As UInteger
        End Function

#End Region

#Region "SendMessage methods"
        <DllImport("user32.dll", EntryPoint:="SendMessageW", CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)> _
        Public Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, _
                                        ByRef htInfo As TCHITTESTINFO) As IntPtr
        End Function
        <DllImport("user32.dll", EntryPoint:="SendMessageW", CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)> _
        Public Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, _
                                        ByVal lParam As IntPtr) As IntPtr
        End Function
#End Region

        <DllImport("user32.dll", EntryPoint:="RealGetWindowClassW", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode)> _
        Public Function RealGetWindowClass(ByVal hWnd As IntPtr, ByVal ClassName As StringBuilder, _
                                               ByVal ClassNameMax As UInteger) As UInteger
        End Function

#Region "API Structures"
        <StructLayout(LayoutKind.Sequential)> _
        Public Structure POINT
            Public x As Integer, y As Integer
        End Structure

        <StructLayout(LayoutKind.Sequential)> _
        Public Structure TCHITTESTINFO
            Public pt As POINT
            Public flags As UInteger
        End Structure

        <StructLayout(LayoutKind.Sequential)> _
        Public Structure WINDOWPOS
            Public hwnd As IntPtr, hwndInsertAfter As IntPtr
            Public x As Integer, y As Integer, cx As Integer, cy As Integer, flags As Integer
        End Structure
#End Region

#Region "Messages"
        Public Const TCM_HITTEST As Integer = &H130D, WM_SETFONT As Integer = &H30, _
        WM_THEMECHANGED As Integer = &H31A, WM_DESTROY As Integer = &H2, WM_NCDESTROY As Integer = &H82, _
        WM_WINDOWPOSCHANGING As Integer = &H46, WM_PARENTNOTIFY As Integer = &H210, _
        WM_CREATE As Integer = &H1, WM_MOUSEMOVE As Integer = &H200, WM_LBUTTONDOWN As Integer = &H201
#End Region

    End Module
End Namespace
